home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / aplictns / mandel10 / part03 < prev    next >
Internet Message Format  |  1991-02-18  |  57KB

  1. Path: news.larc.nasa.gov!amiga-request
  2. From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v91i019: Mandel 1.0 - yet another mandelbrot, Part03/04
  4. Reply-To: dm@stekt.oulu.fi (Hannu Helminen ti)
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga:v91i019@ab20.larc.nasa.gov>
  7. References: <comp.sources.amiga:v91i017@ab20.larc.nasa.gov>
  8. Date: 18 Feb 91 22:25:43 GMT
  9. Approved: tadguy@uunet.UU.NET (Tad Guy)
  10. X-Mail-Submissions-To: amiga@uunet.uu.net
  11. X-Post-Discussions-To: comp.sys.amiga.misc
  12.  
  13. Submitted-by: dm@stekt.oulu.fi (Hannu Helminen ti)
  14. Posting-number: Volume 91, Issue 019
  15. Archive-name: applications/mandel-1.0/part03
  16.  
  17. #!/bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 3 (of 4)."
  24. # Contents:  source/brot.asm source/gui.asm.aa
  25. # Wrapped by tadguy@ab20 on Mon Feb 18 17:25:40 1991
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'source/brot.asm' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'source/brot.asm'\"
  29. else
  30. echo shar: Extracting \"'source/brot.asm'\" \(26440 characters\)
  31. sed "s/^X//" >'source/brot.asm' <<'END_OF_FILE'
  32. X
  33. X* This file: brot version 1.00
  34. X
  35. X* (c) 1990 by H. Helminen
  36. X
  37. X* This program will draw Mandelbrot set.
  38. X* It uses two advanced features:
  39. X
  40. X* 1) Contour Crawling
  41. X*    When this feature is enabled, I will follow the edge
  42. X*    of each area of same colour and assume the interior
  43. X*    is of same color. This is true for ideal set, but because
  44. X*    of digital sampling, some errors may occur.
  45. X*    NOTE: This method is very sensitive to errors that may occur
  46. X*          if you change the code, e.g.
  47. X*    o   pixel colors must not be changed during draw
  48. X*    o   draw must not go out of screen bounds
  49. X*    o   if screen is not clear prior to drawing,
  50. X*        uncleared areas may be left untouched
  51. X*    o   draw must start at an edge of the picture
  52. X
  53. X*    If disabled, every single pixel is calculated individually
  54. X*    resulting a bit better accuracy, a lot slower computing time.
  55. X*    When drawing disconnected Julia sets, crawling should be
  56. X*    disabled since it would produce inaccurate pictures.
  57. X*    Setting the AUTOCRAWL bit in mb_flags will do that for you.
  58. X
  59. X* 2) 32-bit fixed point arithmetics
  60. X*    To speed this program up (standard A500 with 68000 and no
  61. X*    FP-processors) while keeping reasonable resolution, I used
  62. X*    signed 32-bit fixed point arithmetics, shifted left by 29
  63. X*    bits. Multiplication was somewhat cumbersome.
  64. X*    This format allows a resolution of about 1.9 x 10^(-9).
  65. X*    When the resolution needed is much less accurate, one can use
  66. X*    only 16 bits in multiplication. Typically one would use
  67. X*    16 bits when delta > 0.0001 .. 0.0005.
  68. X
  69. X*    Setting the AUTOPREC flag in mb_flags will do that for you.
  70. X*    However, in order to produce accurate pictures of Julia sets
  71. X*    that have complex structure near origo, you may need to
  72. X*    set the HIGH flag by yourself.
  73. X
  74. X* Typical computing times for whole set with 100 iterations
  75. X* (5-bitplane 320 x 256 lores screen, no competing 68000 activity)
  76. X
  77. X*        crawl  walk (=traditional pixel-by-pixel method)
  78. X* 16-bit  0:49   2:12
  79. X* 32-bit  1:29   5:33
  80. X
  81. X* And, of course, the author:
  82. X
  83. X* |_|_  _   _|    _  _  _  _  _   _ _  _  ,|_ _  _
  84. X* (_| )(/_ (_|(_|| )(_|(/_(_)| ) | ) )(_|/)(_(/_|
  85. X*                    _)
  86. X* Hannu Helminen so-dm@stekt.oulu.fi
  87. X
  88. X* This proggie is quite useless by itself.
  89. X* You should (b)link it with pipe.o (by me, of course).
  90. X* Or you could use stack.o, which may be visually more attractive
  91. X* but uses more memory.
  92. X* This proggie is full of references to "stack", please ignore.
  93. X
  94. X* You could use brot with your own programs. Just pass
  95. X* a valid MandelBrot structure in a0 with all fields initialized.
  96. X* (see mbrot.i) The RastPort's *must* have valid TmpRas and AreaInfo
  97. X* structures attached to it.
  98. X
  99. X* Or, link it with gui.o (again by me)
  100. X
  101. X* BUGS: MANY, including:
  102. X
  103. X* - not very smart handling of AUTOCRAWL, since non-connected
  104. X*   set _could_ be crawled provided that before areafilling an
  105. X*   area, a few points in the interior were checked to make sure
  106. X*   that they are of same color.
  107. X* - AUTOPREC will fail on Julia sets with complex structre near origo.
  108. X
  109. X   NOLIST
  110. X   INCLUDE  "macros.i"
  111. X   INCLUDE  "mbrot.i"
  112. X
  113. X   XREF     _AbsExecBase
  114. X
  115. X* If you insist... poof, you can remove the equates and use includes.
  116. X* I however prefer shorter compiles.
  117. X
  118. X
  119. X* These are used to maintain a stack-like dynamically allocated structure.
  120. X* (I like these functions ... only entry points are visible to this proggie)
  121. X
  122. X   XREF     f_push
  123. X   XREF     f_pull
  124. X   XREF     f_clear
  125. X
  126. X* Now make myself visible to others.
  127. X
  128. X   XDEF     MandelBrot
  129. X
  130. X   LIST
  131. X
  132. X
  133. X
  134. X   SECTION  main,CODE
  135. X
  136. XMandelBrot:
  137. X         push     d0-d7/a0-a6
  138. X
  139. X* Save mbrot structure to a4. It can stay there all the time...
  140. X         move.l   a0,a4
  141. X
  142. X         move.l   _AbsExecBase,a6
  143. X         lea      GfxName,a1
  144. X         moveq    #0,d0
  145. X
  146. X         Call     OpenLibrary
  147. X         tst.l    d0
  148. X         beq      exit_mb
  149. X         move.l   d0,a6
  150. X
  151. X* If precision is AUTOPREC, determine which precision we actually use.
  152. X         btst.b   #MBB_AUTOPREC,mb_flags(a4)
  153. X         beq.s    skip_low
  154. X         bset.b   #MBB_HIGH,mb_flags(a4)
  155. X
  156. X         cmp.l    #DELTALIMIT,mb_dx(a4)
  157. X         blo.s    skip_low
  158. X         cmp.l    #DELTALIMIT,mb_dy(a4)
  159. X         blo.s    skip_low
  160. X         bclr.b   #MBB_HIGH,mb_flags(a4)
  161. X
  162. Xskip_low:
  163. X
  164. X* If AUTOCRAWL is set, determine whether we should crawl or no.
  165. X         btst.b   #MBB_AUTOCRAWL,mb_flags(a4)
  166. X         beq.s    skip_crawl
  167. X         bset.b   #MBB_CRAWL,mb_flags(a4)
  168. X
  169. X* Mandelbrot set is always connected, so it may be crawled
  170. X         btst.b   #MBB_JULIA,mb_flags(a4)
  171. X         beq.s    skip_crawl
  172. X
  173. X* Julia set should be crawled if and only if corresponding
  174. X* c = jx + jy i belongs to Mandelbrot set.
  175. X* LS: like that "if and only if"?
  176. X         move.l   mb_jx(a4),d6
  177. X         move.l   mb_jy(a4),d7
  178. X         move.w   mb_i(a4),d3    ; use same number of iterations
  179. X
  180. X         bsr      iterate
  181. X         tst.w    d3
  182. X         bmi.s    skip_crawl     ; inside the set!
  183. X
  184. X         bclr.b   #MBB_CRAWL,mb_flags(a4)
  185. X
  186. Xskip_crawl:
  187. X
  188. X* clear area prior to drawing.
  189. X         move.l   mb_RastPort(a4),a5
  190. X         move.l   a5,a1
  191. X         move.w   #CLEAR,d0
  192. X         Call     SetAPen
  193. X         move.l   a5,a1
  194. X         move.w   mb_x1(a4),d0
  195. X         move.w   mb_y1(a4),d1
  196. X         move.w   mb_x2(a4),d2
  197. X         move.w   mb_y2(a4),d3
  198. X         Call     RectFill
  199. X
  200. X* start drawing...
  201. X         btst.b   #MBB_CRAWL,mb_flags(a4)
  202. X         beq.s    walk_mb
  203. X
  204. X         bsr      Crawling
  205. X         bra.s    exit_mb
  206. Xwalk_mb:
  207. X         bsr      Walking
  208. Xexit_mb:
  209. X         move.l   a6,a1
  210. X         move.l   _AbsExecBase,a6
  211. X         Call     CloseLibrary
  212. X         pull     d0-d7/a0-a6
  213. Xno_gfx:
  214. X         rts
  215. X
  216. XWalking:
  217. X         move.w   mb_x1(a4),d4
  218. X         move.w   mb_y1(a4),d5
  219. X         move.w   d4,d6
  220. X         move.w   mb_x2(a4),d7
  221. X         move.w   mb_y2(a4),d3
  222. X1$:
  223. X
  224. X         bsr      Pixel
  225. X         bsr      Break
  226. X         bne.s    3$
  227. X         addq.w   #1,d4
  228. X         cmp.w    d7,d4
  229. X         blo.s    1$
  230. X         bsr      Pixel
  231. X
  232. X         addq.w   #1,d5
  233. X         cmp.w    d3,d5
  234. X         bhi.s    3$
  235. X2$:
  236. X         bsr      Pixel
  237. X         bsr      Break
  238. X         bne.s    3$
  239. X         subq.w   #1,d4
  240. X         cmp.w    d6,d4
  241. X         bhi.s    2$
  242. X         bsr      Pixel
  243. X
  244. X         addq.w   #1,d5
  245. X         cmp.w    d3,d5
  246. X         bls.s    1$
  247. X3$:
  248. X         rts
  249. X
  250. X
  251. XCrawling:
  252. X         move.w   mb_y1(a4),d0
  253. X         or.w     #%1100000000000000,d0   ; initial direction down
  254. X         swap     d0
  255. X         move.w   mb_x1(a4),d0
  256. X1$:
  257. X         bsr.s    Crawl    ; return with Z clear if user issued break
  258. X         bne.s    2$
  259. X         bsr      f_pull
  260. X         bne.s    1$       ; stack non-empty
  261. X
  262. X2$:
  263. X* Clear stack ... important in case someone used ^C
  264. X         bsr      f_clear
  265. X         rts
  266. X
  267. X
  268. X* "Crawl" is supposed to take care of the actual crawling.
  269. X* When handed with a pixel & direction in d0, it will find
  270. X* its way through the edge of area with same colour.
  271. X
  272. X* In addition, it will push all pixels _not_ in that area
  273. X* to stack.
  274. X
  275. X* d0 format: ddyyyyyy yyyyyyyy xxxxxxxx xxxxxxxx
  276. X
  277. X* direction bits:
  278. X*     00
  279. X*   01  10
  280. X*     11
  281. X
  282. X
  283. XCrawl:
  284. X         push     d0-d7
  285. X         move.w   d0,d4       ; x
  286. X         swap     d0
  287. X         move.w   d0,d5
  288. X         and.w    #%0011111111111111,d5   ; y
  289. X         move.w   d0,d3
  290. X         and.w    #%1100000000000000,d3   ; d (high 2 bits)
  291. X
  292. X* If all pixels are drawn, it seems to me this area has already been
  293. X* crawled (if not so, there are other pixels in the stack...)
  294. X         bsr      Test4
  295. X         tst.w    d0
  296. X         bpl.s    1$          ; All pixels next to me were drawn
  297. X
  298. X         move.w   d4,d6    ; Save place & dir until come to same place again
  299. X         move.w   d5,d7
  300. X         move.w   d3,d2
  301. X
  302. X         move.l   a5,a1
  303. X         move.l   d4,d0
  304. X         move.l   d5,d1
  305. X         bsr      AreaMove    ; note: This is a subroutine, not library call
  306. X2$:
  307. X         bsr.s    proceed
  308. X         move.l   a5,a1
  309. X         move.l   d4,d0
  310. X         move.l   d5,d1
  311. X         bsr      AreaDraw    ; and so is this
  312. X         bsr      Break
  313. X         bne.s    3$
  314. X         cmp.w    d4,d6       ; Compare with initial place & direction
  315. X         bne.s    2$
  316. X         cmp.w    d5,d7
  317. X         bne.s    2$
  318. X         cmp.w    d3,d2
  319. X         bne.s    2$
  320. X
  321. X         move.l   a5,a1
  322. X         move.l   d4,d0
  323. X         move.l   d5,d1
  324. X         Call     ReadPixel
  325. X         move.l   a5,a1
  326. X         Call     SetAPen     ; Just in case no pixels were drawn above.
  327. X         move.l   a5,a1
  328. X         bsr      AreaEnd     ; this
  329. X1$:      moveq    #0,d0
  330. X         bra.s    4$
  331. X3$:
  332. X         move.l   a5,a1
  333. X         bsr      AreaEnd     ; This finishes any draw (subroutine)
  334. X         moveq    #-1,d0
  335. X4$:
  336. X         pull     d0-d7
  337. X         rts                  ; This routine returns same as Break
  338. X
  339. X
  340. X* Proceed: This routine finds edge of an area of uniform color.
  341. X* d4/d5 = pixel, d3 = direction. Returns next pixel & direction
  342. X* along the edge.
  343. X* Lets give an example: let's assume current pixel is A. (a colour)
  344. X* X is known to be != A. b and c are yet unknown.
  345. X* Last direction was up.
  346. X*
  347. X* b c
  348. X* A X
  349. X*
  350. X* check b
  351. X* if (A != b) then
  352. X*    direction = left
  353. X*    push b
  354. X* else
  355. X*    check c
  356. X*    if (A != c) then
  357. X*       current pixel = b
  358. X*       push c
  359. X*    else
  360. X*       direction = right
  361. X*       current pixel = c
  362. X*
  363. X
  364. Xproceed:
  365. X         push     d0/d2/d6-d7
  366. X         bsr      Pixel
  367. X         move.w   d0,d2    ; color of current pixel
  368. X
  369. X         move.w   d4,d6
  370. X         move.w   d5,d7    ; save normal pixel so we can resume
  371. X
  372. X         bsr.s    front
  373. X         bsr      Pixel    ; check "b"
  374. X         cmp.w    d0,d2
  375. X         beq.s    1$
  376. X
  377. X* Turn left.
  378. X         tst.w    d3
  379. X         bpl.s    2$
  380. X         eor.w    #%0100000000000000,d3
  381. X2$:
  382. X         add.w    #%0100000000000000,d3
  383. X         bpl.s    3$
  384. X         eor.w    #%0100000000000000,d3
  385. X3$:
  386. X* Luckily, d3/d6/d7 now contain just right info for pushing.
  387. X         tst.w    d0
  388. X         bmi.s    7$       ; do not push if pixel was outside
  389. X         tst.l    d0
  390. X         bmi.s    7$       ; if pixel drawn, dont push it.
  391. X         move.w   d5,d0
  392. X         or.w     d3,d0
  393. X         eor.w    #%1100000000000000,d0   ; opposite direction
  394. X         swap     d0
  395. X         move.w   d4,d0
  396. X         bsr      f_push
  397. X7$:
  398. X         move.w   d6,d4    ; resume pixel
  399. X         move.w   d7,d5
  400. X         bra.s    4$       ; DONE...
  401. X
  402. X1$:
  403. X         move.w   d4,d6    ; save "forwarded" pixel so we can resume
  404. X         move.w   d5,d7
  405. X
  406. X         bsr.s    right
  407. X         bsr      Pixel    ; check "c"
  408. X         cmp.w    d0,d2
  409. X         beq.s    5$
  410. X
  411. X* Go forward
  412. X* This is what I call luck: again the right components for pushing
  413. X         tst.w    d0
  414. X         bmi.s    8$       ; again, if outside, dont push.
  415. X         tst.l    d0
  416. X         bmi.s    8$       ; dont push drawn pixels either
  417. X         move.w   d5,d0
  418. X         or.w     d3,d0
  419. X         eor.w    #%1100000000000000,d0
  420. X         swap     d0
  421. X         move.w   d4,d0
  422. X         bsr      f_push
  423. X8$:
  424. X         move.w   d6,d4    ; resumes pixel to what it was before 'bsr right'
  425. X         move.w   d7,d5
  426. X         bra.s    4$       ; DONE
  427. X
  428. X5$:
  429. X* Turn to right
  430. X         tst.w    d3
  431. X         bpl.s    6$
  432. X         eor.w    #%0100000000000000,d3
  433. X6$:
  434. X         add.w    #%1100000000000000,d3
  435. X         bpl.s    4$
  436. X         eor.w    #%0100000000000000,d3
  437. X4$:
  438. X         pull     d0/d2/d6-d7
  439. X         rts
  440. X
  441. X* move one pixel d3-wards.
  442. Xfront:
  443. X         tst.w    d3
  444. X         bmi.s    1$
  445. X         btst.w   #14,d3
  446. X         bne.s    2$
  447. X
  448. X         subq.w   #1,d5    ; 00
  449. X         rts
  450. X2$:      subq.w   #1,d4    ; 01
  451. X         rts
  452. X1$:
  453. X         btst.w   #14,d3
  454. X         bne.s    3$
  455. X         addq.w   #1,d4    ; 10
  456. X         rts
  457. X3$:      addq.w   #1,d5    ; 11
  458. X         rts
  459. X
  460. X* move one pixel to the right of direction d3.
  461. Xright:
  462. X         tst.w    d3
  463. X         bmi.s    1$
  464. X         btst.w   #14,d3
  465. X         bne.s    2$
  466. X
  467. X         addq.w   #1,d4    ; 00
  468. X         rts
  469. X2$:      subq.w   #1,d5    ; 01
  470. X         rts
  471. X1$:
  472. X         btst.w   #14,d3
  473. X         bne.s    3$
  474. X         addq.w   #1,d5    ; 10
  475. X         rts
  476. X3$:      subq.w   #1,d4    ; 11
  477. X         rts
  478. X
  479. X* Test4 will test if all 4 pixels next to d4,d5 are drawn.
  480. X* If so, a negative number will be returned in d0.
  481. X
  482. XTest4:
  483. X         move.l   d3,-(a7)
  484. X         moveq    #0,d3
  485. X
  486. X         subq.w   #1,d4
  487. X         bsr.s    GetPixel
  488. X         or.w     d0,d3       ; if any of these is negative ...
  489. X
  490. X         addq.w   #2,d4
  491. X         bsr.s    GetPixel
  492. X         or.w     d0,d3       ; (meaning pixel was not drawn) ...
  493. X         subq.w   #1,d4
  494. X
  495. X         subq.w   #1,d5
  496. X         bsr.s    GetPixel
  497. X         or.w     d0,d3       ; -1 will get written all over d3
  498. X
  499. X         addq.w   #2,d5
  500. X         bsr.s    GetPixel
  501. X         or.w     d0,d3
  502. X         subq.w   #1,d5
  503. X
  504. X         move.w   d3,d0
  505. X         move.l   (a7)+,d3
  506. X         rts
  507. X
  508. X* This routine is also called with screen pixel in d4,d5.
  509. X* (GfxBase = a6, RastPort = a5)
  510. X* It will return pixel color in d0 (but NOT draw it)
  511. X* If pixel is outside region, 0 will be returned.
  512. X* If it is not drawn, -1 will be returned
  513. X
  514. XGetPixel:
  515. X         push     d1/a0-a1
  516. X         moveq    #0,d0      ; d0 will be ready just in case any
  517. X         cmp.w    mb_x1(a4),d4       ; of the conditions below is met
  518. X         blo      1$
  519. X         cmp.w    mb_x2(a4),d4
  520. X         bhi      1$
  521. X         cmp.w    mb_y1(a4),d5
  522. X         blo      1$
  523. X         cmp.w    mb_y2(a4),d5
  524. X         bhi      1$
  525. X
  526. X         move.l   a5,a1
  527. X         move.l   d4,d0
  528. X         move.l   d5,d1
  529. X         Call     ReadPixel
  530. X
  531. X         cmp.w    #CLEAR,d0
  532. X         bne.s    1$
  533. X
  534. X         moveq    #-1,d0
  535. X1$:
  536. X         pull     d1/a0-a1
  537. X         rts
  538. X
  539. X* This routine is called with screen pixel in d4,d5.
  540. X* (GfxBase = a6, RastPort = a5)
  541. X* It will return pixel color in d0 and draw it if required.
  542. X* If pixel is outside drawing region, -1 will be returned.
  543. X
  544. X* (An undocumented feature: if pixel was drawn before this
  545. X* routine was called, bit 31 will be set.)
  546. X
  547. X* Another feature: pixels right of y-axis are returned
  548. X* with bit 14 set (unless color == interior).
  549. X* This will make separate areas on both sides of y-axis,
  550. X* thus making it impossible to accidentally crawl around
  551. X* the set (without noticing the interior at all)...
  552. X
  553. XPixel:
  554. X         push     d1-d3/d6-d7/a0-a1
  555. X         moveq    #0,d2
  556. X         moveq    #-1,d0      ; d0 will be ready just in case any
  557. X         cmp.w    mb_x1(a4),d4       ; of the conditions below is met
  558. X         blo      pixel_outofbounds
  559. X         cmp.w    mb_x2(a4),d4
  560. X         bhi      pixel_outofbounds
  561. X         cmp.w    mb_y1(a4),d5
  562. X         blo      pixel_outofbounds
  563. X         cmp.w    mb_y2(a4),d5
  564. X         bhi      pixel_outofbounds
  565. X
  566. X         move.w   d4,d3
  567. X         move.w   d3,d6
  568. X         mulu     mb_dx(a4),d6   ; dx.hi * d2
  569. X         swap     d6             ; calmly ignore any overflow
  570. X         move.w   #0,d6
  571. X         mulu     2+mb_dx(a4),d3 ; dx.lo * d2
  572. X         add.l    d3,d6
  573. X         add.l    mb_x0(a4),d6
  574. X         bmi.s    pixel_left
  575. X         move.w   #%0100000000000000,d2
  576. Xpixel_left:
  577. X         move.l   a5,a1
  578. X         move.l   d4,d0
  579. X         move.l   d5,d1
  580. X         Call     ReadPixel
  581. X
  582. X         bset     #31,d0
  583. X         cmp.w    #CLEAR,d0
  584. X         bne.s    pixel_outofbounds       ; not clear -> dont draw (OBS! d0 still has color)
  585. X
  586. X         move.w   d5,d3
  587. X         move.w   d3,d7
  588. X         mulu     mb_dy(a4),d7
  589. X         swap     d7
  590. X         move.w   #0,d7
  591. X         mulu     2+mb_dy(a4),d3
  592. X         add.l    d3,d7
  593. X         neg.l    d7       ; upwards increasing y coordinate
  594. X         add.l    mb_y0(a4),d7
  595. X
  596. X         move.w   mb_i(a4),d3
  597. X         sub.w    #2,d3
  598. X         bpl.s    positive_i
  599. X         moveq    #0,d3
  600. Xpositive_i
  601. X         bsr.s    iterate
  602. X
  603. X         cmp.w    #-1,d3
  604. X         beq.s    pixel_inside_set
  605. X
  606. X         and.l    #$ffff,d3
  607. X         divu     mb_colors(a4),d3
  608. X         swap     d3          ; remainder
  609. X         add.w    #FIRST,d3
  610. X         bra.s    pixel_outside_set
  611. Xpixel_inside_set:
  612. X         move.w   #INTERIOR,d3
  613. Xpixel_outside_set:
  614. X         move.w   d3,d0
  615. X         move.l   a5,a1
  616. X         Call     SetAPen
  617. X         move.w   d4,d0
  618. X         move.w   d5,d1
  619. X         move.l   a5,a1
  620. X         Call     WritePixel
  621. X         move.w   d3,d0
  622. X         bclr     #31,d0
  623. Xpixel_outofbounds:
  624. X         cmp.w    #INTERIOR,d0
  625. X         beq.s    pixel_dontOR
  626. X         or.w     d2,d0
  627. Xpixel_dontOR:
  628. X         pull     d1-d3/d6-d7/a0-a1
  629. X         rts
  630. X
  631. X
  632. X* This is the soul of the MandelBrot set.
  633. X* We iterate a point represented by x=d6 and y=d7 in our
  634. X* numerical system. d3 is set to maximum number of iterations,
  635. X* and will be decremented until -1 reached unless point is
  636. X* found to be outside the set.
  637. X* We find the point to be outside when |z| > 2
  638. X
  639. X* There are two versions of this routine, the former for 32 bits,
  640. X* the latter for 16 bits.
  641. X
  642. X* For those who don't know the formula of Mandelbrot set:
  643. X*
  644. X* Point c = x + yi {x,y E R, i^2 = -1} is said to be in the M. set if
  645. X*          2
  646. X* z    = z   + c    , z  = c,
  647. X*  n+1    n            0
  648. X*
  649. X* doesnt -> oo as n -> oo. (This routine is only approximation, n -> d3)
  650. X
  651. X* NEW: If client wants the user to see Julia sets, we handle them here.
  652. X* The formula is the same, except: z0 is point and c is constant
  653. X* throughout the set (it corresponds to a point in the M. set).
  654. X* Hope you can complex math!
  655. X
  656. X
  657. Xiterate:
  658. X         btst.b   #MBB_HIGH,mb_flags(a4)
  659. X         beq      iterate16
  660. X
  661. X         push     d0-d2/d4-d7
  662. X
  663. X* z is initialized with c
  664. X         move.l   d6,d4    ; x0 -> x
  665. X         move.l   d7,d5    ; y0 -> y
  666. X
  667. X* Julia stuff!
  668. X         btst.b   #MBB_JULIA,mb_flags(a4)
  669. X         beq.s    1$
  670. X         move.l   mb_jx(a4),d6
  671. X         move.l   mb_jy(a4),d7
  672. X1$:
  673. X* real part
  674. X* (And as an intermission, find out if x^2 + y^2 > 2^2 or |z| > 2.
  675. X*  Because our multiplication routine does not monitor overflow,
  676. X*  we check the arguments first.)
  677. X
  678. X         move.l   d4,d0
  679. X         bsr      square
  680. X         move.l   d1,d2    ; x^2
  681. X         add.l    d0,d0    ; |x| > 2 ?  d0 was reserved
  682. X         bvs.s    3$
  683. X
  684. X         move.l   d5,d0
  685. X         bsr      square     ; y^2
  686. X         add.l    d0,d0    ; |y| > 2 ?
  687. X         bvs.s    3$
  688. X         move.l   d1,d0    ; |z| > 2 ?
  689. X         add.l    d2,d0
  690. X         bvs.s    3$
  691. X
  692. X         sub.l    d1,d2    ; x^2 - y^2
  693. X         add.l    d6,d2    ;           + x0
  694. X         bvs.s    2$
  695. X
  696. X* imaginary part
  697. X         move.l   d4,d0
  698. X         move.l   d5,d1
  699. X         bsr      multi
  700. X         add.l    d1,d1    ; 2 * x * y
  701. X         bvs.s    2$
  702. X         add.l    d7,d1                + y0
  703. X         bvs.s    2$
  704. X
  705. X* get ready for next iteration:
  706. X         move.l   d1,d5
  707. X         move.l   d2,d4
  708. X
  709. X         dbf      d3,1$
  710. X
  711. X* This is more or less a kludge!
  712. X* Testing if |z| < 2 should be last in our loop, before
  713. X* dbf. Because it was first, low-level iterations
  714. X* would show some sharp edges on the interior.
  715. X* We need one more |z| < 2 here.
  716. X* (The kludge is not removed because of speed reasons.)
  717. X
  718. X         move.l   d4,d0
  719. X         bsr      square
  720. X         move.l   d1,d2    ; x^2
  721. X         add.l    d0,d0    ; |x| > 2 ?
  722. X         bvs.s    3$
  723. X
  724. X         move.l   d5,d0
  725. X         bsr      square   ; y^2
  726. X         add.l    d0,d0    ; |y| > 2 ?
  727. X         bvs.s    3$
  728. X         add.l    d2,d1    ; |z| > 2 ?
  729. X         bvc.s    2$
  730. X
  731. X* Thanks to our kludge, d3 has been decremented too much if
  732. X* branched here. This would result in sharp edges on areas
  733. X* outside the set as well. This time we have an easy fix:
  734. X
  735. X3$:      addq.w   #1,d3
  736. X2$:
  737. X         pull     d0-d2/d4-d7
  738. X         rts
  739. X
  740. X* Square and multi are primary operations of signed fixed-point math.
  741. X* Addition can be done using normal add.l instruction.
  742. X
  743. X* This routine does not monitor overflowing.
  744. X* Its arguments are expected to be within the range -2 .. 2.
  745. X
  746. X* NOTE: all registers except d1 are preserved (including d0!)
  747. X
  748. X* square : d0^2 -> d1
  749. X* multi: d0*d1 -> d1
  750. X
  751. Xsquare:  move.l   d0,d1
  752. Xmulti:   push     d2-d5
  753. X
  754. X* We can only multiply with unsigned numbers.
  755. X* So we calculate the sign of the result ahead of time.
  756. X
  757. X         move.l   d0,d2
  758. X         bpl.s    1$
  759. X         neg.l    d0       ; fix d0
  760. X1$:
  761. X         tst.l    d1
  762. X         bpl.s    2$
  763. X         neg.l    d1       ; fix d1
  764. X         not.l    d2       ; but d2 has the sign of final result
  765. X2$:
  766. X         move.w   d1,d3
  767. X         mulu     d0,d3    ; d3 = d0lo * d1lo
  768. X         moveq    #29,d5   ; strip this much bits out of d3
  769. X         lsr.l    d5,d3    ; (introduces rounding error of max. 1 bits)
  770. X
  771. X         swap     d0
  772. X         move.w   d1,d4
  773. X         mulu     d0,d4    ; d4 = d0h1 * d1lo
  774. X         moveq    #13,d5   ; again some strip-tease
  775. X         lsr.l    d5,d4    ; (and rounding errors)
  776. X         add.l    d4,d3
  777. X
  778. X         swap     d1
  779. X         move.w   d1,d4
  780. X         mulu     d0,d4    ; d4 = d0hi * d1hi
  781. X         lsl.l    #3,d4    ; now shift the other way up
  782. X         add.l    d4,d3    ; if (-2)*(-2) this will overflow .. who cares?
  783. X
  784. X         swap     d0
  785. X         mulu     d0,d1    ; d1 = d0lo * d1hi
  786. X         lsr.l    d5,d1    ; shift .. d5 still has #13
  787. X         add.l    d1,d3    ; all summed in d3
  788. X
  789. X         tst.l    d2
  790. X         bpl.s    3$       ; test & fix sign of product
  791. X         neg.l    d3
  792. X3$:
  793. X         move.l   d3,d1    ; result will be carried back in d1 (!)
  794. X         pull     d2-d5
  795. X         rts
  796. X
  797. X* The same routine with .w and with no bsr's to multi/square.
  798. X* Comments have been stripped out, only changed parts are recommented.
  799. X
  800. XMULTI    macro
  801. X            muls     d0,d1
  802. X            asl.l    #3,d1
  803. X            swap     d1
  804. X         endm
  805. XSQUARE   macro
  806. X            move.w   d0,d1
  807. X            muls     d0,d1
  808. X            asl.l    #3,d1
  809. X            swap     d1
  810. X         endm
  811. X
  812. Xiterate16:
  813. X         push     d0-d2/d4-d7
  814. X         swap     d6          ; long -> word
  815. X         swap     d7
  816. X
  817. X         move.w   d6,d4
  818. X         move.w   d7,d5
  819. X
  820. X         btst.b   #MBB_JULIA,mb_flags(a4)
  821. X         beq.s    1$
  822. X         move.w   mb_jx(a4),d6   ; always remember: we want HIGH order bits
  823. X         move.w   mb_jy(a4),d7
  824. X1$:
  825. X         move.w   d4,d0
  826. X         SQUARE
  827. X         move.w   d1,d2
  828. X         add.w    d0,d0
  829. X         bvs.s    3$
  830. X         move.w   d5,d0
  831. X         SQUARE
  832. X         add.w    d0,d0
  833. X         bvs.s    3$
  834. X         move.w   d1,d0
  835. X         add.w    d2,d0
  836. X         bvs.s    3$
  837. X         sub.w    d1,d2
  838. X         add.w    d6,d2
  839. X         bvs.s    2$
  840. X
  841. X         move.w   d4,d0
  842. X         move.w   d5,d1
  843. X         MULTI
  844. X         add.w    d1,d1
  845. X         bvs.s    2$
  846. X         add.w    d7,d1
  847. X         bvs.s    2$
  848. X         move.w   d1,d5
  849. X         move.w   d2,d4
  850. X         dbf      d3,1$
  851. X
  852. X         muls     d5,d5    ; This part is slightly different
  853. X         muls     d4,d4
  854. X         add.l    d5,d4
  855. X         bvs.s    3$
  856. X         add.l    d4,d4
  857. X         add.l    d4,d4
  858. X         bvs.s    3$
  859. X         add.l    d4,d4
  860. X         bvc.s    2$
  861. X
  862. X3$:      addq.w   #1,d3
  863. X2$:
  864. X         pull     d0-d2/d4-d7
  865. X         rts
  866. X
  867. X* General-purpose break-condition check.
  868. X* Current version uses call-back procedures, because I could
  869. X* not make it general enough.
  870. XBreak:
  871. X         push     a0/d0
  872. X         move.l   mb_break(a4),d0
  873. X         beq.s    1$
  874. X         move.l   d0,a0
  875. X         jsr      (a0)
  876. X1$:
  877. X         pull     a0/d0
  878. X         rts
  879. X
  880. X* This group of routines essentially remove unnecessary points
  881. X* and then call the real AreaXXXX routines.
  882. X* Just because 6553 vectors seems to be a maximum.
  883. X
  884. X* One could code this by allocating one bitplane, setting bits accorging
  885. X* to what is fed to AreaDraw, filling it with one raw blitter operation
  886. X* and then BlitPattern()ing it to RastPort. This would save allocating
  887. X* TmpRas and AreaInfo structures.
  888. X
  889. X* I am a perfectionist, but I aint a fool. This is a kludge, but so what?
  890. X
  891. XAreaMove:
  892. X         move.w   d0,startx
  893. X         move.w   d1,starty
  894. X         move.w   d0,prevx
  895. X         move.w   d1,prevy
  896. X         clr.b    dir
  897. X         Call     AreaMove
  898. X         rts
  899. XAreaDraw:
  900. X         push     d2/d3
  901. X         bsr.s    which_dir
  902. X
  903. X         tst.b    dir
  904. X         bpl.s    skip_it
  905. X
  906. X* Now! All bits are not on same line.
  907. X* More accurately, since we test this on every point, the current
  908. X* point is not on same line as the previous ones. So:
  909. X         move.w   d0,d2
  910. X         move.w   d1,d3
  911. X         move.w   prevx,d0    ; The previous was the last in line
  912. X         move.w   prevy,d1
  913. X         move.w   d0,startx   ; starting point of the new line
  914. X         move.w   d1,starty
  915. X         Call     AreaDraw
  916. X         move.w   d2,d0       ; one-stage pipelining
  917. X         move.w   d3,d1
  918. X         clr.b    dir
  919. X         bsr.s    which_dir   ; right direction for these first 2 bits.
  920. Xskip_it:
  921. X         move.w   d0,prevx
  922. X         move.w   d1,prevy
  923. Xdraw_done:
  924. X         pull     d2/d3
  925. X         rts
  926. X
  927. X* This routine keeps track of our heading.
  928. X* dir carries the direction from previous stages, all 8 directions
  929. X* are mapped to numbers 1..4 (opposite directions get same number).
  930. X* If directions is undetermined so far, dir is 0.
  931. X* -1 means pixels are no more on same line (requires AreaDraw.)
  932. Xwhich_dir:
  933. X         move.w   startx,d2
  934. X         move.w   starty,d3
  935. X         sub.w    d0,d2
  936. X         sub.w    d1,d3
  937. X
  938. X         tst.w    d2       ; normalize (make opposite dirs equal)
  939. X         bpl.s    pos_1
  940. X         neg.w    d2
  941. X         neg.w    d3
  942. Xpos_1
  943. X         tst.w    d3
  944. X         bpl.s    pos_2
  945. X         neg.w    d2
  946. X         neg.w    d3
  947. Xpos_2
  948. X
  949. X         tst.w    d2       ; now determine direction.
  950. X         beq.s    dir_03
  951. X         bpl.s    dir_12
  952. X;dir4
  953. X         add.w    d2,d3
  954. X         bne.s    dir_illegal ; not diagonal!
  955. X         moveq    #4,d2
  956. X         bra.s    dir_proc
  957. Xdir_12
  958. X         tst.w    d3
  959. X         beq.s    dir_1
  960. X;dir_2
  961. X         cmp.w    d2,d3
  962. X         bne.s    dir_illegal ; not diagonal!
  963. X         moveq    #2,d2
  964. X         bra.s    dir_proc
  965. Xdir_1
  966. X         moveq    #1,d2
  967. X         bra.s    dir_proc
  968. Xdir_03
  969. X         tst.w    d3
  970. X         beq.s    dir_0
  971. X;dir_3
  972. X         moveq    #3,d2
  973. X         bra.s    dir_proc
  974. Xdir_0
  975. X         moveq    #0,d2
  976. X         bra.s    dir_proc
  977. Xdir_illegal
  978. X         moveq    #-1,d2
  979. Xdir_proc
  980. X         move.b   dir,d3
  981. X         beq.s    dir_valid
  982. X         tst.b    d2
  983. X         beq.s    dir_OK
  984. X         cmp.b    d2,d3
  985. X         beq.s    dir_OK
  986. X;neither valid!
  987. X         move.b   #-1,dir
  988. X         rts
  989. Xdir_valid
  990. X         move.b   d2,dir
  991. Xdir_OK
  992. X         rts
  993. X
  994. X
  995. XAreaEnd:
  996. X         move.l   a1,-(a7)
  997. X         move.w   prevx,d0
  998. X         move.w   prevy,d1
  999. X         Call     AreaDraw    ; force dirty buffers out
  1000. X         move.l   (a7)+,a1
  1001. X         Call     AreaEnd
  1002. X         rts
  1003. X
  1004. X* Needed by my Area routines
  1005. X
  1006. Xprevx       ds.w  1
  1007. Xprevy       ds.w  1
  1008. Xstartx      ds.w  1
  1009. Xstarty      ds.w  1
  1010. Xdir         ds.b  1
  1011. X
  1012. X* perhaps this should be a section of its own.
  1013. X
  1014. XGfxName     dc.b  'graphics.library',0
  1015. X
  1016. X         end
  1017. X
  1018. END_OF_FILE
  1019. if test 26440 -ne `wc -c <'source/brot.asm'`; then
  1020.     echo shar: \"'source/brot.asm'\" unpacked with wrong size!
  1021. fi
  1022. # end of 'source/brot.asm'
  1023. fi
  1024. if test -f 'source/gui.asm.aa' -a "${1}" != "-c" ; then 
  1025.   echo shar: Will not clobber existing file \"'source/gui.asm.aa'\"
  1026. else
  1027. echo shar: Extracting \"'source/gui.asm.aa'\" \(26145 characters\)
  1028. sed "s/^X//" >'source/gui.asm.aa' <<'END_OF_FILE'
  1029. X
  1030. X* This file: gui v1.00
  1031. X
  1032. X* (c) 1990 by H. Helminen
  1033. X
  1034. X* linkage information:
  1035. X* blink gui.o brot.o pipe.o to mandel lib amiga.lib
  1036. X
  1037. X* And now for something completely different:
  1038. X* A graphical user interface for MandelBrot.
  1039. X
  1040. X* of course by The DM (Hannu Helminen, dm@stekt.oulu.fi)
  1041. X
  1042. X* BUGS: many, including
  1043. X* - coordinates in screen title may trash window title bar
  1044. X* - if not enough memory, 56 bytes will disappear.
  1045. X
  1046. X            NOLIST
  1047. X            INCLUDE  "macros.i"
  1048. X            INCLUDE  "mbrot.i"
  1049. X            INCLUDE  "iff.i"
  1050. X            INCLUDE  "exec/lists.i"
  1051. X            INCLUDE  "exec/memory.i"
  1052. X            INCLUDE  "exec/ports.i"
  1053. X            INCLUDE  "exec/alerts.i"
  1054. X            INCLUDE  "devices/timer.i"
  1055. X            INCLUDE  "libraries/dos.i"
  1056. X            INCLUDE  "libraries/dosextens.i"
  1057. X            INCLUDE  "intuition/screens.i"
  1058. X            INCLUDE  "intuition/intuition.i"
  1059. X            INCLUDE  "workbench/workbench.i"
  1060. X            INCLUDE  "workbench/startup.i"
  1061. X
  1062. X            XREF     _LVOAlert
  1063. X
  1064. X* Misc defines
  1065. X
  1066. XDEPTH       EQU   5     ; # of bitplanes (use at least 3 (2 is minimum))
  1067. XSCREEN      EQU   0
  1068. X
  1069. X* SCREEN: Select one of the following:
  1070. X
  1071. X*        non-lace lace
  1072. X* lores     0       2
  1073. X* hires     1       3
  1074. X
  1075. X* SCREEN determines VIEWMODE, screen size and mb_dx/mb_dy scaling.
  1076. X* NOTE: if SCREEN > 0, max. magnification will be 28
  1077. X
  1078. X         ifeq  SCREEN-0
  1079. XVIEWMODE    EQU   0
  1080. XXSIZE       EQU   320      ; Size of screen
  1081. XYSIZE       EQU   256
  1082. X         endc
  1083. X         ifeq  SCREEN-1
  1084. XVIEWMODE    EQU   V_HIRES
  1085. XXSIZE       EQU   640
  1086. XYSIZE       EQU   256
  1087. X         endc
  1088. X         ifeq  SCREEN-2
  1089. XVIEWMODE    EQU   V_LACE
  1090. XXSIZE       EQU   320
  1091. XYSIZE       EQU   512
  1092. X         endc
  1093. X         ifeq  SCREEN-3
  1094. XVIEWMODE    EQU   V_HIRES|V_LACE
  1095. XXSIZE       EQU   640
  1096. XYSIZE       EQU   512
  1097. X         endc
  1098. X
  1099. XWINX        EQU   20      ; Place & size of info window
  1100. XWINY        EQU   20
  1101. XWINW        EQU   148
  1102. XWINH        EQU   80
  1103. X
  1104. XRASSIZE     EQU   ((XSIZE+15)/16*2)*YSIZE
  1105. XMAXVECT     EQU   6553  ; Cant get bigger than this. (Sigh.)
  1106. X
  1107. XNORMAL_X    EQU   0
  1108. XNORMAL_Y    EQU   0
  1109. XNORMAL_JX   EQU   0
  1110. XNORMAL_JY   EQU   0
  1111. XNORMAL_I    EQU   100
  1112. XNORMAL_ZOOM EQU   $010000
  1113. XNORMAL_M    EQU   $060000
  1114. XMIN_M       EQU   $050000
  1115. X
  1116. X         ifeq  SCREEN
  1117. XMAX_M       EQU   $1d0000
  1118. X         endc
  1119. X         ifgt  SCREEN
  1120. XMAX_M       EQU   $1c0000
  1121. X         endc
  1122. X
  1123. XFLAGS1      EQU   ACTIVATE|BACKDROP|BORDERLESS|REPORTMOUSE|RMBTRAP|NOCAREREFRESH
  1124. XFLAGS2      EQU   WINDOWCLOSE|WINDOWDRAG|RMBTRAP|NOCAREREFRESH
  1125. X
  1126. XIDCMP1      EQU   MOUSEMOVE|MOUSEBUTTONS|RAWKEY
  1127. XIDCMP2      EQU   GADGETUP|GADGETDOWN|CLOSEWINDOW|RAWKEY
  1128. X
  1129. XFAKECLASS   EQU   3  ; This pretends to be one of IDCMP classes
  1130. X
  1131. XZOOM        EQU   0  ; these internal tokens represent method of zooming
  1132. XREDRAW      EQU   1
  1133. XRESET       EQU   2
  1134. X
  1135. XTRUE        EQU   1
  1136. XFALSE       EQU   0
  1137. X
  1138. X* Import brot entry point
  1139. X            XREF  MandelBrot
  1140. X
  1141. X* A simple macro that converts letters to upper case
  1142. Xtoupper  macro
  1143. X         cmp.b #'a',\1
  1144. X         blo.s no\@
  1145. X         sub.b #'a'-'A',\1
  1146. Xno\@:    ds.w  0           ; needed for assembler's sake.
  1147. X         endm
  1148. X
  1149. X
  1150. X            LIST
  1151. X
  1152. X
  1153. X            SECTION  main,CODE
  1154. X
  1155. X* This is where the actual code begins.
  1156. X         push     d1-d7/a0-a6
  1157. X
  1158. X         move.l   a0,a3
  1159. X         move.w   d0,d3
  1160. X
  1161. X* We need to find out whether we have been invoked from CLI or WorkBench
  1162. X         sub.l    a1,a1
  1163. X         Base     Exec
  1164. X         Call     FindTask
  1165. X         move.l   d0,a0          ; This is a process, right?
  1166. X         move.l   pr_CLI(a0),d0
  1167. X         beq.s    from_WB
  1168. X
  1169. X         clr.b    -1(a3,d3.w)
  1170. X         clr.l    WBmessage      ; from CLI
  1171. X         move.l   d0,a0
  1172. X         add.l    a0,a0          ; BPTR conversion
  1173. X         add.l    a0,a0
  1174. X         move.l   cli_CommandName(a0),a0  ; BSTR
  1175. X         add.l    a0,a0          ; BPTR conversion
  1176. X         add.l    a0,a0          ; now here we'll find a BCPL string...
  1177. X         move.b   (a0)+,d0       ; get len and goto first character
  1178. X         move.l   a0,MyName      ; save name
  1179. X         ext.w    d0
  1180. X         move.w   d0,MyNameLen   ; and length
  1181. X
  1182. X         bra.s    common_code
  1183. Xfrom_WB:
  1184. X         lea      pr_MsgPort(a0),a3
  1185. X         move.l   a3,a0
  1186. X         Call     WaitPort
  1187. X         move.l   a3,a0
  1188. X         Call     GetMsg
  1189. X         move.l   d0,WBmessage   ; Do not reply until ready to exit.
  1190. X
  1191. X         move.l   d0,a0
  1192. X         move.l   sm_ArgList(a0),d0 ; Argument list
  1193. X         beq.s    common_code
  1194. X         move.l   d0,a0
  1195. X         move.l   wa_Lock(a0),d2    ; lock to current directory
  1196. X         move.l   wa_Name(a0),a0
  1197. X         move.l   a0,MyName         ; save name
  1198. X         moveq    #-1,d1
  1199. X1$
  1200. X         addq.w   #1,d1
  1201. X         tst.b    (a0)+
  1202. X         bne.s    1$
  1203. X         move.w   d1,MyNameLen      ; and length
  1204. X
  1205. Xcommon_code:
  1206. X
  1207. X* Open some libraries
  1208. X         lea      _DosLib,a1
  1209. X         moveq    #0,d0
  1210. X         Call     OpenLibrary
  1211. X         move.l   d0,_DosBase
  1212. X         bne.s    dos_ok
  1213. X         ALERT    AG_OpenLib|AO_DOSLib
  1214. X         bra      nodos
  1215. Xdos_ok:
  1216. X         tst.l    WBmessage
  1217. X         beq.s    1$
  1218. X         move.l   d2,d1
  1219. X         Base     Dos
  1220. X         Call     CurrentDir
  1221. X         Base     Exec
  1222. X1$
  1223. X         lea      _IntuitionLib,a1
  1224. X         moveq    #0,d0
  1225. X         Call     OpenLibrary
  1226. X         move.l   d0,_IntuitionBase
  1227. X         bne.s    intui_ok
  1228. X         ALERT    AG_OpenLib|AO_Intuition
  1229. X         bra      nointui
  1230. Xintui_ok:
  1231. X         lea      _GfxLib,a1
  1232. X         moveq    #0,d0
  1233. X         Call     OpenLibrary
  1234. X         move.l   d0,_GfxBase
  1235. X         bne.s    gfx_ok
  1236. X         ALERT    AG_OpenLib|AO_GraphicsLib
  1237. X         bra      nogfx
  1238. Xgfx_ok:
  1239. X
  1240. X* Open timer.device
  1241. X         lea      _TimerDev,a0
  1242. X         moveq    #UNIT_VBLANK,d0
  1243. X         lea      IOreq,a1
  1244. X         moveq    #0,d1
  1245. X         Call     OpenDevice
  1246. X         tst.b    d0
  1247. X         beq.s    timer_ok
  1248. X         ALERT    AG_OpenDev|AO_TimerDev
  1249. X         bra      timererr
  1250. Xtimer_ok:
  1251. X* initialize msgport
  1252. X         lea      MsgPort,a2
  1253. X         move.b   #NT_MSGPORT,LN_TYPE(a2)
  1254. X         clr.b    LN_PRI(a2)
  1255. X         clr.l    LN_NAME(a2)
  1256. X         move.b   #PA_SIGNAL,MP_FLAGS(a2)    ; signal me when done
  1257. X
  1258. X         moveq    #-1,d0
  1259. X         move.b   #ERROR_nosignal,error
  1260. X         Call     AllocSignal          ; get a signal bit
  1261. X         tst.b    d0
  1262. X         bmi      nosignal
  1263. X         move.b   d0,MP_SIGBIT(a2)
  1264. X
  1265. X         sub.l    a1,a1
  1266. X         Call     FindTask
  1267. X         move.l   d0,MP_SIGTASK(a2)
  1268. X                                       ; task to be signalled
  1269. X         lea      MP_MSGLIST(a2),a0
  1270. X         NEWLIST  a0                   ; init link fields
  1271. X         lea      IOreq,a0
  1272. X         move.l   a2,MN_REPLYPORT(a0)
  1273. X         clr.l    UseReq               ; mark it as not being in use
  1274. X
  1275. X         move.l   a3,a0
  1276. X
  1277. X         lea      MyMandelBrot,a4
  1278. X
  1279. X         move.w   #0,mb_x1(a4)
  1280. X         move.w   #0,mb_y1(a4)
  1281. X         move.w   #XSIZE-1,mb_x2(a4)
  1282. X         move.w   #YSIZE-1,mb_y2(a4)
  1283. X
  1284. X* Defaults
  1285. X         move.b   #ERROR_none,error
  1286. X         move.w   #NORMAL_I,mb_i(a4)
  1287. X         move.b   #MBF_AUTOPREC|MBF_AUTOCRAWL,mb_flags(a4)
  1288. X         move.b   #TRUE,inter
  1289. X         move.b   #ZOOM,method
  1290. X         clr.b    isdrawn
  1291. X         clr.w    Counter
  1292. X         clr.b    saveit
  1293. X
  1294. X         move.l   #NORMAL_ZOOM,Zoom    ; 2^(-1) = 50%
  1295. X         move.l   #NORMAL_M,Magnify    ; 2^(-6) = 1/64
  1296. X         move.l   #NORMAL_X,CurrentX
  1297. X         move.l   #NORMAL_Y,CurrentY
  1298. X         move.l   #NORMAL_JX,mb_jx(a4)
  1299. X         move.l   #NORMAL_JY,mb_jy(a4)
  1300. X
  1301. X         lea      CtrlC,a1
  1302. X         move.l   a1,mb_break(a4)   ; Call-back procedure
  1303. X
  1304. X         move.w   #(1<<DEPTH)-2,mb_colors(a4)
  1305. X
  1306. X* This is again WB/CLI specific code, option processing
  1307. X         tst.l    WBmessage
  1308. X         beq      CLI_1
  1309. X
  1310. X* WB option stuff
  1311. X         Base     Exec
  1312. X         lea      _IconLib,a1
  1313. X         moveq    #0,d0
  1314. X         Call     OpenLibrary
  1315. X         tst.l    d0
  1316. X         bne.s    iconlib_ok
  1317. X* Currently this error is not reported...
  1318. X         move.b   #ERROR_iconlib,error
  1319. X         bra      options_done
  1320. Xiconlib_ok
  1321. X         move.l   d0,a6
  1322. X         move.l   MyName,a0
  1323. X         Call     GetDiskObject
  1324. X         tst.l    d0
  1325. X         bne.s    diskobject_ok
  1326. X         move.b   #ERROR_noicon,error
  1327. X         bra.s    close_icon_lib
  1328. Xdiskobject_ok
  1329. X         move.l   d0,a5          ; disk object
  1330. X         lea      WBjumptable,a2
  1331. X         lea      WBoptions,a3
  1332. Xbrowse_tools
  1333. X         tst.b    (a3)              ; The last in line?
  1334. X         beq.s    icons_done
  1335. X         move.l   do_ToolTypes(a5),a0
  1336. X         move.l   a3,a1
  1337. X         Call     FindToolType
  1338. X         move.l   (a2)+,a1          ; The actual address to jump to
  1339. X         tst.l    d0
  1340. X         beq.s    tool_notfound
  1341. X         move.l   d0,a0
  1342. X         jsr      (a1)
  1343. X         beq.s    wrong_option
  1344. Xtool_notfound
  1345. X         tst.b    (a3)+
  1346. X         bne.s    tool_notfound     ; Find next tool type
  1347. X         bra.s    browse_tools
  1348. Xwrong_option
  1349. X         move.b   #ERROR_tooltype,error
  1350. Xicons_done
  1351. X         move.l   a5,a0
  1352. X         Call     FreeDiskObject
  1353. Xclose_icon_lib
  1354. X         move.l   a6,a1
  1355. X         Base     Exec
  1356. X         Call     CloseLibrary
  1357. X         tst.b    error
  1358. X         bne      nosignal
  1359. X         bra.s    options_done
  1360. X
  1361. XCLI_1
  1362. X         lea      LongUsage,a3
  1363. X         move.l   #LongLen,d3
  1364. X         tst.b    (a0)
  1365. X         beq.s    options_done
  1366. X         cmp.b    #'?',(a0)
  1367. X         beq.s    usage
  1368. X
  1369. X         move.b   #ERROR_cmdline,error
  1370. X         lea      ShortUsage,a3
  1371. X         move.l   #ShortLen,d3
  1372. Xgetnext:
  1373. X         move.b   (a0)+,d0
  1374. X         beq.s    options_done
  1375. X         cmp.b    #' ',d0
  1376. X         beq.s    getnext
  1377. X         cmp.b    #8,d0
  1378. X         beq.s    getnext
  1379. X         cmp.b    #'-',d0
  1380. X         bne.s    usage
  1381. X
  1382. X         move.b   (a0)+,d0
  1383. X         lea      options,a1
  1384. X         lea      jumptable,a2
  1385. X
  1386. X         toupper  d0
  1387. Xgetopt:
  1388. X         move.l   (a2)+,a5
  1389. X         cmp.b    (a1)+,d0
  1390. X         bne.s    next
  1391. X         jsr      (a5)
  1392. X         beq.s    usage          ; a result of zero means wrong option
  1393. X         bra.s    getnext
  1394. Xnext:
  1395. X         tst.b    (a1)
  1396. X         bne.s    getopt
  1397. Xusage:
  1398. X         Base     Dos
  1399. X         Call     Output
  1400. X         move.l   d0,d1
  1401. X         move.l   a3,d2
  1402. X         Call     Write
  1403. X         bra      noscreen       ; draw nothing
  1404. Xoptions_done:
  1405. X
  1406. X* Screen to display the new map.
  1407. X         lea      MyNewScreen,a0
  1408. X         Base     Intuition
  1409. X         Call     OpenScreen
  1410. X         move.b   #ERROR_noscreen,error
  1411. X         move.l   d0,MyScreen
  1412. X         beq      noscreen
  1413. X         move.l   d0,a2
  1414. X
  1415. X         move.l   a2,InsertScreen1
  1416. X         move.l   a2,InsertScreen2
  1417. X
  1418. X         lea      sc_ViewPort(a2),a3
  1419. X
  1420. X* First window that takes over entire screen
  1421. X         lea      MyNewWindow1,a0
  1422. X         Call     OpenWindow
  1423. X         move.b   #ERROR_nowindow,error
  1424. X         move.l   d0,MyWindow1
  1425. X         beq      nowindow
  1426. X
  1427. X* This version fetches windows rastport.
  1428. X         move.l   d0,a0
  1429. X         move.l   wd_RPort(a0),a2
  1430. X         move.l   a2,mb_RastPort(a4)
  1431. X
  1432. X         move.l   a3,a0
  1433. X         lea      Colors,a1
  1434. X         moveq    #(1<<DEPTH),d0
  1435. X         Base     Gfx
  1436. X         Call     LoadRGB4
  1437. X
  1438. X* Now get a TmpRas to screen
  1439. X         move.l   #RASSIZE,d0
  1440. X         moveq    #MEMF_CHIP,d1
  1441. X         move.l   d1,d2
  1442. X         Base     Exec
  1443. X         Call     AllocMem
  1444. X         move.b   #ERROR_nomem,error
  1445. X         move.l   d0,Mem1
  1446. X         beq      nomem1
  1447. X         lea      MyTmpRas,a3
  1448. X         move.l   d0,a1
  1449. X         move.l   a3,a0
  1450. X         move.l   d2,d0
  1451. X         Base     Gfx
  1452. X         Call     InitTmpRas
  1453. X         move.l   a3,rp_TmpRas(a2)
  1454. X
  1455. X         move.l   #MAXVECT*5,d0
  1456. X         moveq    #0,d1
  1457. X         Base     Exec
  1458. X         Call     AllocMem
  1459. X         move.l   d0,Mem2
  1460. X         beq      nomem2
  1461. X         lea      MyAreaInfo,a3
  1462. X         move.l   a3,a0
  1463. X         move.l   d0,a1
  1464. X         move.l   #MAXVECT,d0
  1465. X         Base     Gfx
  1466. X         Call     InitArea
  1467. X         move.l   a3,rp_AreaInfo(a2)
  1468. X
  1469. X         move.b   #ERROR_none,error
  1470. X* main loop if 'interactive'
  1471. Xloop:
  1472. X         move.l   Magnify,d0
  1473. X         move.l   #MAX_M,d1
  1474. X         cmp.l    d1,d0
  1475. X         bls.s    1$
  1476. X         move.l   d1,d0
  1477. X1$:
  1478. X         move.l   #MIN_M,d1
  1479. X         cmp.l    d1,d0
  1480. X         bhs.s    2$
  1481. X         move.l   d1,d0
  1482. X2$:
  1483. X         move.l   d0,Magnify
  1484. X         bsr      Transform
  1485. X         move.l   Magnify,OldMagnify
  1486. X
  1487. X* This is why we did all the above... and will be doing all the below...
  1488. X* Draw mandelbrot!
  1489. X         move.l   a4,a0
  1490. X         jsr      MandelBrot
  1491. X
  1492. X         tst.b    inter
  1493. X         beq      exit        ; user didnt want us to be interactive.
  1494. X
  1495. X* A friend of mine once pointed out that the doings of my
  1496. X* programs are often commented to be done by "we". Don't know why.
  1497. X
  1498. X* Perhaps I think my program is a person, and we are doing the
  1499. X* thing together, I by designing the program, and the program
  1500. X* in turn by running it.
  1501. X
  1502. X* One of these days, I may actually begin to talk to my programs.
  1503. X* Is that all right to you, my tiny little proggie?
  1504. X
  1505. X         bsr      calculate
  1506. Xreopen:
  1507. X* Open another window
  1508. X         lea      MyNewWindow2,a0
  1509. X         Base     Intuition
  1510. X         Call     OpenWindow
  1511. X         move.l   d0,MyWindow2
  1512. X         beq      exit_dont_save      ; could not get memory
  1513. X* Thenafter, refresh allll gadgets.
  1514. X
  1515. X* This gives refresh_m and refresh_z a hassle-free operation
  1516. X         move.b   method,d7
  1517. X         move.b   #RESET,method
  1518. X
  1519. X         move.l   CurrentX,d0
  1520. X         bsr      refresh_x
  1521. X         move.l   CurrentY,d0
  1522. X         bsr      refresh_y
  1523. X         move.l   Magnify,d0
  1524. X         bsr      refresh_m
  1525. X         move.w   mb_i(a4),d0
  1526. X         bsr      refresh_i
  1527. X         move.l   Zoom,d0
  1528. X         bsr      refresh_z
  1529. X
  1530. X         move.b   d7,method
  1531. X
  1532. X         bsr      refresh_set
  1533. X         bsr      refresh_zoom   ; this does also DrawGrid
  1534. X
  1535. Xmsgloop:
  1536. X         bsr      GetMessage
  1537. X         bne      exitloop        ; nonzero if user issued break
  1538. Xgotmessage:
  1539. X         Base     Intuition
  1540. X         cmp.l    #CLOSEWINDOW,d2
  1541. X         bne.s    no_close
  1542. X
  1543. X
  1544. X* Info window is about to be closed. Hide also title bar.
  1545. X         move.l   MyWindow2,a0
  1546. X
  1547. X* This copies both LeftEdge and TopEdge to NewWindow structure
  1548. X* This way when the window is opened again, it will be in same place.
  1549. X         move.l   wd_LeftEdge(a0),MyNewWindow2
  1550. X         Call     CloseWindow
  1551. X         clr.l    MyWindow2   ; This window is closed
  1552. X         move.l   MyScreen,a0
  1553. X         moveq    #FALSE,d0
  1554. X         Call     ShowTitle
  1555. X         bsr      RemoveGrid
  1556. X
  1557. X* Resume when either button pressed
  1558. Xget_it:  bsr      GetMessage
  1559. X         bne      exit        ; break, no need to close window
  1560. X         cmp.l    #MOUSEBUTTONS,d2
  1561. X         bne.s    get_it      ; wait for it to happen
  1562. X
  1563. X* Restore all
  1564. X         bsr      DrawGrid
  1565. X         move.l   MyScreen,a0
  1566. X         moveq    #TRUE,d0
  1567. X         Base     Intuition
  1568. X         Call     ShowTitle
  1569. X         bra      reopen      ; resume window
  1570. X
  1571. X
  1572. Xno_close:
  1573. X         cmp.l    #MOUSEMOVE,d2
  1574. X         bne.s    no_move
  1575. X         bsr      dispCoords  ; All we do here is to display current
  1576. X         bra.s    msgloop     ; coordinates
  1577. X
  1578. X
  1579. Xno_move:
  1580. X         cmp.l    #MOUSEBUTTONS,d2
  1581. X         bne.s    no_buttons
  1582. X         cmp.w    #SELECTDOWN,d3
  1583. X         bne.s    no_left_button
  1584. X         bsr      LeftButton     ; 3 things might get returned:
  1585. X         beq      msgloop     ; finished
  1586. X         bmi      exitloop    ; ^C
  1587. X         bra      zoom_draw   ; There has been a double-click -> Draw!
  1588. Xno_left_button:
  1589. X         cmp.w    #MENUDOWN,d3
  1590. X         bne.s    no_buttons
  1591. X         bsr      RightButton
  1592. X         bne      exitloop
  1593. X         bra      msgloop
  1594. Xno_buttons:
  1595. X
  1596. X         cmp.w    #GADGETDOWN,d2
  1597. X         bne.s    no_gadg_down
  1598. X         move.w   gg_GadgetID(a5),d1   ; Gadget's ID.
  1599. X         move.w   d1,d0
  1600. X         and.w    #STRING,d0
  1601. X         beq.s    not_string_gadget
  1602. X
  1603. X         bsr      StringGadgetDown  ; we also get one message here.
  1604. X         bne      exitloop          ; sigh. (l)user wants to get rid of us
  1605. X         bra      gotmessage        ; yeah, we've already got one.
  1606. Xnot_string_gadget:
  1607. X         bsr      OtherGadgetDown   ; Three things might return from this:
  1608. X         bmi.s    zoom_draw         ; negative if zoom
  1609. X         bne      exitloop          ; positive if exit
  1610. X
  1611. Xno_gadg_down:
  1612. X         cmp.l    #RAWKEY,d2
  1613. X         bne.s    no_rawkey
  1614. X         cmp.w    #$21,d3           ; RAW key code for 'S'
  1615. X         bne.s    no_rawkey
  1616. X         btst     #IEQUALIFIERB_CONTROL,d4
  1617. X         beq.s    no_rawkey
  1618. X         move.l   MyWindow2,a0
  1619. X         move.l   wd_LeftEdge(a0),MyNewWindow2  ; See previous CloseWindow
  1620. X         Call     CloseWindow
  1621. X         clr.l    MyWindow2      ; This window is closed
  1622. X         move.l   MyScreen,a0
  1623. X         moveq    #FALSE,d0
  1624. X         Call     ShowTitle
  1625. X         bsr      RemoveGrid
  1626. X
  1627. X         bsr      SavePicture
  1628. X
  1629. X         bsr      DrawGrid
  1630. X         move.l   MyScreen,a0
  1631. X         moveq    #TRUE,d0
  1632. X         Base     Intuition
  1633. X         Call     ShowTitle
  1634. X         bra      reopen      ; open window again
  1635. X
  1636. Xno_rawkey:
  1637. X         bra      msgloop           ; and zero if nothing
  1638. X
  1639. Xzoom_draw:
  1640. X         move.l   MyWindow2,a0
  1641. X         Base     Intuition
  1642. X         move.l   wd_LeftEdge(a0),MyNewWindow2  ; See previous CloseWindow
  1643. X         Call     CloseWindow
  1644. X         bsr      RemoveGrid
  1645. X         cmp.b    #ZOOM,method
  1646. X         beq.s    1$
  1647. X         cmp.b    #REDRAW,method
  1648. X         beq.s    2$
  1649. X         move.l   #NORMAL_M,Magnify
  1650. X         move.l   #NORMAL_X,CurrentX
  1651. X         move.l   #NORMAL_Y,CurrentY
  1652. X         bra      loop
  1653. X1$:
  1654. X         move.l   Zoom,d0
  1655. X         add.l    d0,Magnify
  1656. X2$:
  1657. X         bra      loop
  1658. X
  1659. X
  1660. X
  1661. X
  1662. Xexitloop:
  1663. X* Close window
  1664. X         move.l   MyWindow2,a0
  1665. X         Base     Intuition
  1666. X         Call     CloseWindow
  1667. X         bsr      RemoveGrid
  1668. X
  1669. X* Leave ship
  1670. Xexit:
  1671. X* If non-interactive and user explicitely set -s option, save picture.
  1672. X         tst.b    inter
  1673. X         bne.s    exit_dont_save
  1674. X         tst.b    saveit
  1675. X         beq.s    exit_dont_save
  1676. X         bsr      SavePicture
  1677. Xexit_dont_save
  1678. X         move.l   MyScreen,a0
  1679. X         moveq    #FALSE,d0
  1680. X         Base     Intuition
  1681. X         Call     ShowTitle
  1682. X
  1683. X         move.l   Mem2,a1
  1684. X         move.l   #5*MAXVECT,d0
  1685. X         Base     Exec
  1686. X         Call     FreeMem
  1687. Xnomem2:
  1688. X         move.l   Mem1,a1
  1689. X         move.l   #RASSIZE,d0
  1690. X         Base     Exec
  1691. X         Call     FreeMem
  1692. Xnomem1:
  1693. X         Base     Intuition
  1694. X         move.l   MyWindow1,a0
  1695. X         Call     CloseWindow
  1696. Xnowindow:
  1697. X         move.l   MyScreen,a0
  1698. X         Call     CloseScreen
  1699. Xnoscreen:
  1700. X         lea      MsgPort,a0
  1701. X         move.b   MP_SIGBIT(a0),d0
  1702. X         Base     Exec
  1703. X         Call     FreeSignal
  1704. Xnosignal:
  1705. X         lea      IOreq,a1
  1706. X         Call     CloseDevice
  1707. Xtimererr:
  1708. X         move.l   _GfxBase,a1
  1709. X         Call     CloseLibrary
  1710. Xnogfx:
  1711. X         move.l   _IntuitionBase,a1
  1712. X         Call     CloseLibrary
  1713. Xnointui:
  1714. X         tst.b    error
  1715. X         beq.s    close_dos   ; no error
  1716. X
  1717. X         Base     Dos
  1718. X         tst.l    WBmessage
  1719. X         beq.s    CLI_2
  1720. X         lea      stdout_name,a0
  1721. X         move.l   a0,d1
  1722. X         move.l   #MODE_NEWFILE,d2
  1723. X         Call     Open
  1724. X         tst.l    d0
  1725. X         beq.s    close_dos
  1726. X         bra.s    common_code2
  1727. XCLI_2
  1728. X         Call     Output
  1729. Xcommon_code2
  1730. X         move.l   d0,d4       ; save file handle for further use
  1731. X
  1732. X* First, output our name.
  1733. X         move.l   d4,d1
  1734. X         move.l   MyName,d2
  1735. X         move.w   MyNameLen,d3
  1736. X         ext.l    d3
  1737. X         Call     Write
  1738. X
  1739. X* Then, the error message.
  1740. X         move.l   d4,d1
  1741. X         move.b   error,d0
  1742. X         ext.w    d0
  1743. X         lsl.w    #2,d0
  1744. X         lea      errors,a0
  1745. X         move.l   0(a0,d0.w),a0
  1746. X         move.l   a0,d2
  1747. X         moveq    #-1,d3
  1748. X1$
  1749. X         addq.l   #1,d3
  1750. X         tst.b    (a0)+
  1751. X         bne.s    1$
  1752. X         Call     Write
  1753. X
  1754. X         tst.l    WBmessage
  1755. X         beq.s    close_dos
  1756. X         move.l   #2*TICKS_PER_SECOND,d1
  1757. X* REM ALLOW TIME FOR USER TO RELEASE BUTTON FROM LAST PUSH
  1758. X         Call     Delay
  1759. X         move.l   d4,d1
  1760. X         Call     Close       ; close stdout window
  1761. Xclose_dos
  1762. X         Base     Exec
  1763. X         move.l   _DosBase,a1
  1764. X         Call     CloseLibrary
  1765. X         move.l   WBmessage,d0
  1766. X         beq.s    nodos
  1767. X         Call     Forbid
  1768. X         move.l   d0,a1
  1769. X         Call     ReplyMsg       ; Now WB knows we are safe to get rid of
  1770. Xnodos:
  1771. X         moveq    #0,d0
  1772. X         move.b   error,d0
  1773. X         beq.s    2$
  1774. X         moveq    #RETURN_FAIL,d0
  1775. X2$:
  1776. X         pull     d1-d7/a0-a6
  1777. X         rts
  1778. X
  1779. XRemoveGrid:
  1780. X         tst.b    isdrawn
  1781. X         beq      nothing_to_remove
  1782. X
  1783. X         push     d0-d2/a0-a2/a6
  1784. X
  1785. X         Base     Intuition
  1786. X         move.l   MyWindow1,a0
  1787. X         move.l   wd_RPort(a0),a2
  1788. X
  1789. X* DrawGrid has conveniently set up some values for me. How nice of him!
  1790. X         move.w   centerx,d0
  1791. X         move.w   centery,d1
  1792. X         move.l   pic_c,a1
  1793. X         bsr.s    remove_1
  1794. X
  1795. X         move.w   lowx,d0
  1796. X         move.w   lowy,d1
  1797. X         move.l   pic_tl,a1
  1798. X         bsr.s    remove_1
  1799. X
  1800. X         move.w   lowx,d0
  1801. X         move.w   highy,d1
  1802. X         move.l   pic_bl,a1
  1803. X         bsr.s    remove_1
  1804. X
  1805. X         move.w   highx,d0
  1806. X         move.w   lowy,d1
  1807. X         move.l   pic_tr,a1
  1808. X         bsr.s    remove_1
  1809. X
  1810. X         move.w   highx,d0
  1811. X         move.w   highy,d1
  1812. X         move.l   pic_br,a1
  1813. X         bsr.s    remove_1
  1814. X
  1815. X         clr.b    isdrawn
  1816. X         pull     d0-d2/a0-a2/a6
  1817. Xnothing_to_remove:
  1818. X         rts
  1819. X
  1820. Xremove_1:
  1821. X         move.l   a2,a0
  1822. X         move.l   a1,d2
  1823. X         beq.s    1$
  1824. X         Call     DrawBorder
  1825. X1$:      rts
  1826. X
  1827. X
  1828. XDrawGrid:
  1829. X         bsr      RemoveGrid
  1830. X         cmp.b    #ZOOM,method
  1831. X         beq.s    draw_yes
  1832. X         cmp.b    #RESET,method
  1833. X         beq      draw_over
  1834. X         move.l   Magnify,d0
  1835. X         cmp.l    OldMagnify,d0
  1836. X         bne      draw_over
  1837. Xdraw_yes:
  1838. X         push     a0-a2/a6/d0-d7
  1839. X         move.l   prex,d0
  1840. X         move.l   prey,d1
  1841. X         move.b   #TRUE,isdrawn
  1842. X
  1843. X         move.l   d0,prex
  1844. X         move.l   d1,prey
  1845. X         move.l   #$8000,d2      ; round
  1846. X         add.l    d2,d0
  1847. X         add.l    d2,d1
  1848. X
  1849. X         move.l   d0,d4
  1850. X         move.l   d1,d5
  1851. X
  1852. X         swap     d0
  1853. X         swap     d1
  1854. X
  1855. X         moveq    #0,d2          ; record # of crossings
  1856. X         Base     Intuition
  1857. X         lea      Cross,a1
  1858. X         move.l   MyWindow1,a0
  1859. X         move.l   wd_RPort(a0),a2
  1860. X
  1861. X         cmp.w    mb_x1(a4),d0
  1862. X         bge.s    1$
  1863. X         move.w   mb_x1(a4),d0
  1864. X         lea      LeftLeft,a1
  1865. X         addq.w   #1,d2
  1866. X1$:
  1867. X         cmp.w    mb_x2(a4),d0
  1868. X         ble.s    2$
  1869. X         move.w   mb_x2(a4),d0
  1870. X         lea      RightRight,a1
  1871. X         addq.w   #1,d2
  1872. X2$:
  1873. X         cmp.w    mb_y1(a4),d1
  1874. X         bge.s    3$
  1875. X         move.w   mb_y1(a4),d1
  1876. X         lea      UpUp,a1
  1877. X         addq.w   #1,d2
  1878. X3$:
  1879. X         cmp.w    mb_y2(a4),d1
  1880. X         ble.s    4$
  1881. X         move.w   mb_y2(a4),d1
  1882. X         lea      DownDown,a1
  1883. X         addq.w   #1,d2
  1884. X4$:
  1885. X         cmp.w    #1,d2       ; only 1 crossing allowed
  1886. X         bls.s    ok_to_disp
  1887. X         clr.l    pic_c
  1888. X         bra.s    cross_over
  1889. Xok_to_disp:
  1890. X         move.w   d0,centerx
  1891. X         move.w   d1,centery
  1892. X
  1893. X         move.l   a2,a0
  1894. X         move.l   a1,pic_c
  1895. X         Call     DrawBorder
  1896. Xcross_over:
  1897. X         move.w   mb_x2(a4),d0
  1898. X         sub.w    mb_x1(a4),d0
  1899. X         move.l   Zoom,d3
  1900. X
  1901. X         cmp.b    #REDRAW,method ; if redraw, grid has size of screen
  1902. X         bne.s    revolution
  1903. X         moveq    #0,d3
  1904. Xrevolution:
  1905. X         add.l    #$10000,d3
  1906. X         bmi      pig_big
  1907. X
  1908. X         moveq    #0,d1
  1909. X         moveq    #0,d2
  1910. X         bsr      Power2
  1911. X* Hey! What are you doing?
  1912. X* We will find how long the side of the grid should be.
  1913. X* If Zoom < -$10000, it wont fit on the screen same time as
  1914. X* crosshairs. And adding $10000 means halving the distance,
  1915. X* and as it happens, that is just what we want!
  1916. X         move.l   d0,d6
  1917. X
  1918. X         move.w   mb_y2(a4),d0
  1919. X         sub.w    mb_y1(a4),d0
  1920. X         bsr      Power2         ; d1-d3 remain!
  1921. X         move.l   d0,d7
  1922. X
  1923. X         move.l   d4,d2
  1924. X         move.l   d5,d3
  1925. X         sub.l    d6,d2          ; note! d7 has a remainder similar to
  1926. X         sub.l    d7,d3          ; that of d4
  1927. X         add.l    d6,d4
  1928. X         add.l    d7,d5
  1929. X         swap     d2
  1930. X         swap     d3
  1931. X         swap     d4
  1932. X         swap     d5
  1933. X
  1934. X         moveq    #0,d6
  1935. X         move.w   mb_x1(a4),d0
  1936. X         move.w   mb_x2(a4),d1
  1937. X         cmp.w    d0,d2
  1938. X         bge.s    1$
  1939. X         move.w   d0,d2
  1940. X         bset     #0,d6
  1941. X1$:
  1942. X         cmp.w    d1,d2
  1943. X         bgt      pig_big
  1944. X         cmp.w    d1,d4
  1945. X         ble.s    2$
  1946. X         move.w   d1,d4
  1947. X         bset     #1,d6
  1948. X2$:
  1949. X         cmp.w    d0,d4
  1950. X         blt      pig_big
  1951. X         move.w   mb_y1(a4),d0
  1952. X         move.w   mb_y2(a4),d1
  1953. X         cmp.w    d0,d3
  1954. X         bge.s    3$
  1955. X         move.w   d0,d3
  1956. X         bset     #2,d6
  1957. X3$:
  1958. X         cmp.w    d1,d3
  1959. X         bgt      pig_big
  1960. X         cmp.w    d1,d5
  1961. X         ble.s    4$
  1962. X         move.w   d1,d5
  1963. X         bset     #3,d6
  1964. X4$:
  1965. X         cmp.w    d0,d5
  1966. X         blt      pig_big
  1967. X
  1968. X         move.w   d2,lowx
  1969. X         move.w   d3,lowy
  1970. X         move.w   d4,highx
  1971. X         move.w   d5,highy
  1972. X
  1973. X* process the corners.
  1974. X         push     a3-a5    ; NEED some workspace
  1975. X         lea      TopLeft,a1
  1976. X         lea      BottomLeft,a3
  1977. X         lea      TopRight,a4
  1978. X         lea      BottomRight,a5
  1979. X         btst.b   #0,d6
  1980. X         beq      no_left
  1981. X         lea      LeftLeft,a1
  1982. X         move.l   a1,a3
  1983. Xno_left:
  1984. X         btst.b   #1,d6
  1985. X         beq.s    no_right
  1986. X         lea      RightRight,a4
  1987. X         move.l   a4,a5
  1988. Xno_right:
  1989. X         btst.b   #2,d6
  1990. X         beq.s    no_up
  1991. X         lea      UpUp,a1
  1992. X         move.l   a1,a4
  1993. Xno_up:
  1994. X         btst.b   #3,d6
  1995. X         beq.s    no_down
  1996. X         lea      DownDown,a3
  1997. X         move.l   a3,a5
  1998. Xno_down:
  1999. X         not.b    d6
  2000. X         move.b   d6,d0
  2001. X         and.b    #%0101,d0
  2002. X         bne.s    skip_tl
  2003. X         sub.l    a1,a1
  2004. Xskip_tl:
  2005. X         move.b   d6,d0
  2006. X         and.b    #%1001,d0
  2007. X         bne.s    skip_bl
  2008. X         sub.l    a3,a3
  2009. Xskip_bl:
  2010. X         move.b   d6,d0
  2011. X         and.b    #%0110,d0
  2012. X         bne.s    skip_tr
  2013. X         sub.l    a4,a4
  2014. Xskip_tr:
  2015. X         and.b    #%1010,d6
  2016. X         bne.s    skip_br
  2017. X         sub.l    a5,a5
  2018. Xskip_br:
  2019. X         move.l   a2,a0
  2020. X         move.l   a1,pic_tl
  2021. X         beq.s    no_tl
  2022. X         move.w   d2,d0
  2023. X         move.w   d3,d1
  2024. X         Call     DrawBorder
  2025. Xno_tl:
  2026. X         move.l   a3,a1
  2027. X         move.l   a2,a0
  2028. X         move.l   a1,pic_bl
  2029. END_OF_FILE
  2030. if test 26145 -ne `wc -c <'source/gui.asm.aa'`; then
  2031.     echo shar: \"'source/gui.asm.aa'\" unpacked with wrong size!
  2032. fi
  2033. # end of 'source/gui.asm.aa'
  2034. fi
  2035. echo shar: End of archive 3 \(of 4\).
  2036. cp /dev/null ark3isdone
  2037. MISSING=""
  2038. for I in 1 2 3 4 ; do
  2039.     if test ! -f ark${I}isdone ; then
  2040.     MISSING="${MISSING} ${I}"
  2041.     fi
  2042. done
  2043. if test "${MISSING}" = "" ; then
  2044.     echo You have unpacked all 4 archives.
  2045.     rm -f ark[1-9]isdone
  2046. else
  2047.     echo You still need to unpack the following archives:
  2048.     echo "        " ${MISSING}
  2049. fi
  2050. ##  End of shell archive.
  2051. exit 0
  2052. -- 
  2053. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  2054. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  2055. Post requests for sources, and general discussion to comp.sys.amiga.misc.
  2056.